package  common.db.id;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 04.09.2009
 * Time: 12:08:00
 * To change this template use File | Settings | File Templates.
 */
public abstract class GenIdObject<E> implements Identified<E>
{
	private E id;

	public GenIdObject(E id)
	{
		this.id = id;
	}


	protected GenIdObject()
	{
	}

	public E getId()
	{
		return id;
	}

	protected void setId(E id)
	{
		this.id = id;
	}

	@Override
	public int hashCode()
	{
		int result = 17;
		result = 37 * result + (id == null ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (obj == null)
			return false;
		if (!obj.getClass().equals(this.getClass()))
			return false;

		GenIdObject cfg = (GenIdObject)obj;

		return (id == null && cfg.getId() == null && super.equals(obj))
				|| (id != null && id.equals(cfg.getId()));
	}
}
